package com.wenbiao.springcloud.controller;

import com.wenbiao.springcloud.model.User;
import org.springframework.web.bind.annotation.*;

@RestController
public class HelloController {

    @RequestMapping(value = "/service/hello")
    public String hello(){
        //进行业务处理
//        try {
//            Thread.sleep(4000);
//        } catch (InterruptedException e) {
//            e.printStackTrace();
//        }
        System.out.println("服务提供1");
        return "hello spring cloud.Provider1";
    }

    @RequestMapping(value = "/service/user")
    public User user(){
        User user=new User();
        user.setId(1);
        user.setName("二狗");
        user.setPhone("18741786412");
        user.setAge(18);
        return user;
    }

    @RequestMapping(value = "/service/getUser")
    public User getUser(@RequestParam("id")Integer id,
                        @RequestParam("name")String name,
                        @RequestParam("phone")String phone,
                        @RequestParam("age")int age){
        User user=new User();
        user.setId(id);
        user.setName(name);
        user.setPhone(phone);
        user.setAge(age);
        return user;
    }

    @PostMapping(value = "/service/addUser")
    public User addUser(@RequestParam("id")Integer id,
                        @RequestParam("name")String name,
                        @RequestParam("phone")String phone,
                        @RequestParam("age")int age){
        User user=new User();
        user.setId(id);
        user.setName(name);
        user.setPhone(phone);
        user.setAge(age);
        return user;
    }

    @PutMapping(value = "/service/updateUser")
    public void updateUser(@RequestParam("id")Integer id,
                        @RequestParam("name")String name,
                        @RequestParam("phone")String phone,
                        @RequestParam("age")int age){
        User user=new User();
        user.setId(id);
        user.setName(name);
        user.setPhone(phone);
        user.setAge(age);
        System.out.println(user.toString());
    }

    @DeleteMapping(value = "/service/deleteUser")
    public void deleteUser(@RequestParam("id")Integer id,
                           @RequestParam("name")String name,
                           @RequestParam("phone")String phone,
                           @RequestParam("age")int age){
        User user=new User();
        user.setId(id);
        user.setName(name);
        user.setPhone(phone);
        user.setAge(age);
        System.out.println(user.toString());
    }
}
